package hku.cs.eclunuo.views;

import java.util.List;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class TestContentProvider extends ArrayContentProvider implements
		ITreeContentProvider {

	private CheckboxTreeViewer treeViewer;

	@Override
	public Object[] getChildren(Object parentElement) {
		return ((Ltest) parentElement).getChildren().toArray();
	}

	@Override
	public Object getParent(Object element) {
		return ((Ltest) element).getParent();
	}

	@Override
	public boolean hasChildren(Object element) {
		return ((Ltest) element).getChildren().size() > 0;
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		treeViewer = (CheckboxTreeViewer) viewer;
	}

	//	

	public void updateTreeCheck(Ltest t) {
		if (t instanceof LtestSuite){
			treeViewer.setGrayChecked(t, true);
			List<Ltest> ts = t.getChildren();
			for(Ltest test : ts)
				updateTreeCheck(test);
		}

	}

}
